package com.jy.api.controller.wechat;

import com.jy.api.domain.WeChatConfig;
import com.jy.api.wechat.service.Gzh3WxService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxJsapiSignature;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.RandomUtils;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/6/19.
 */


@Slf4j
@RestController
@RequestMapping(value = "wechat", produces = "application/json;charset=utf-8")
public class ScanController {

    @Autowired
    private Gzh3WxService wxService;

    //调用扫一扫
    @RequestMapping(method = RequestMethod.GET, value = "scan")
    public ResponseEntity getSignature(@RequestParam(value = "url") String url) throws WxErrorException {
        WxJsapiSignature wxJsapiSignature = wxService.createJsapiSignature(url);
        Map<String, Object> map = new HashMap<>();
        map.put("appId", wxJsapiSignature.getAppId());
        map.put("timeStamp", wxJsapiSignature.getTimestamp());
        map.put("nonceStr", wxJsapiSignature.getNonceStr());
        map.put("signaTrue", wxJsapiSignature.getSignature());
        return ResponseEntity.ok(map);
    }


}
